import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getDevLocation, getDevIotLocation } from '@gis/lib/api';
// import { openDeviceDialog } from '@/views/equipment-manage/components/overview-info/overview-info-dialog';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import get from 'lodash-es/get.js';
import { netAndScenicDataStore } from '@gis/lib/pinia/netAndScenic.js';
import { openEquipmentRlmjDetailsDialog, openGoodsDeviceDialog } from '../../../../views/equipment/opt.js';
import { openMonitorDetailsDialog } from '../../../../views/monitor/monitor-opt.js';

const typeCodeEnum = {
  D0114_1: 'yangan',
  D0114_2: 'menci',
  D0114_3: 'yinjinggai',
  D0114_4: 'lajitong',
  D0114_5: 'dianqihz',
  // D0114_6: 'yg', //线型可燃气体探测器
  // D0114_7: 'yg', //复合式电气火灾探测器
  // D0114_8: 'yg', //污水监测
  D0114_9: 'youyanjc',
  // D0114_10: 'yyjc', //消防主机
  D0114_11: 'yijianbj',
  D0114_12: 'gkpw',
  zhinengjk: 'zhinengjk',
  menjindz: 'menjindz',
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 52px;height: 96px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {
    if (this.data.type == 'menjindz') {
      openEquipmentRlmjDetailsDialog(this.data);
    } else if (this.data.type == 'zhinengjk') {
      openMonitorDetailsDialog(this.data);
    } else {
      openGoodsDeviceDialog(this.data);
    }
  }
}

export default class Cygzsb extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const { scenicIds, netYardIds } = netAndScenicDataStore();
    const data = await handleCommonRes(
      getDevIotLocation,
      Object.assign(
        {},
        {
          area_code: scenicIds ? scenicIds : area_code,
          yard_id: netYardIds,
        }
      )
    );
    // const devData = await handleCommonRes(
    //   getDevLocation,
    //   Object.assign(
    //     {},
    //     {
    //       area_code: scenicIds && scenicIds.split(',').length == 1 ? scenicIds : area_code,
    //       yard_id: netYardIds,
    //     }
    //   )
    // );
    // const xlgcList = get(devData, 'xlgc', []).map((item) => Object.assign({}, item, { type: 'zhinengjk' }));
    // const rlmjList = get(devData, 'rlmj', []).map((item) => Object.assign({}, item, { type: 'menjindz' }));
    return (
      data
        // .concat(xlgcList)
        // .concat(rlmjList)
        .filter((item) => item.longitude && item.latitude)
        .map((item) => Object.assign({}, item, { lnglat: [item.longitude, item.latitude] }))
    );
  }
}
